package com.ruoyi.web.controller.project;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.Song;
import com.ruoyi.project.service.ISongService;
import com.ruoyi.web.core.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;

/**
 * 音乐曲目 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-01
 */
@Controller
@RequestMapping("/project/song")
public class SongController extends BaseController
{
    private String prefix = "project/song";
	
	@Autowired
	private ISongService songService;
	
	@RequiresPermissions("project:song:view")
	@GetMapping()
	public String song()
	{
	    return prefix + "/song";
	}


	@RequiresPermissions("project:song:view")
	@GetMapping("/data")
	public String songData()
	{
		return prefix + "/song_data";
	}
	
	/**
	 * 查询音乐曲目列表
	 */
	@RequiresPermissions("project:song:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Song song)
	{
		startPage();
        List<Song> list = songService.selectSongList(song);
		return getDataTable(list);
	}
	
	/**
	 * 新增音乐曲目
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存音乐曲目
	 */
	@RequiresPermissions("project:song:add")
	@Log(title = "音乐曲目", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Song song)
	{		
		return toAjax(songService.insertSong(song));
	}

	/**
	 * 修改音乐曲目
	 */
	@GetMapping("/edit/{songId}")
	public String edit(@PathVariable("songId") Long songId, ModelMap mmap)
	{
		Song song = songService.selectSongById(songId);
		mmap.put("song", song);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存音乐曲目
	 */
	@RequiresPermissions("project:song:edit")
	@Log(title = "音乐曲目", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Song song)
	{		
		return toAjax(songService.updateSong(song));
	}
	
	/**
	 * 删除音乐曲目
	 */
	@RequiresPermissions("project:song:remove")
	@Log(title = "音乐曲目", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(songService.deleteSongByIds(ids));
	}
	
}
